-module(active_dets_storage).

-behaviour(active_storage).

-export([open/2, lookup/2, enter/3, delete/2, close/1]).

open(Name, Options) ->
	DetsOptions = lists:filter(fun
		(_) -> false
	end, Options),
	{ok, Table} = dets:open_file(Name, DetsOptions),
	Table.

lookup(Table, Key) ->
	Result = case dets:lookup(Table, Key) of
		[{_, Value}] -> {value, Value};
		_ -> none
	end,
	{Table, Result}.

enter(Table, Key, Value) ->
	catch dets:insert(Table, {Key, Value}),
	Table.

delete(Table, Key) ->
	catch dets:delete(Table, Key),
	Table.

close(Table) ->
	dets:close(Table).

